package com.gjy.quartz.simple;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-08-11 12:23:41
 */
public class SimpleSchedule {

    public static void main(String[] args) throws Exception {
        // 创建调度器
        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();

        // 创建实例
        JobDetail jobDetail = JobBuilder.newJob(PrintTimeJob.class)
                .withIdentity("job1", "group1").build();

        // 创建trigger
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "triggerGroup1")
                .startNow()
                // 每秒执行一次,一直执行
                //.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(3).repeatForever())
                .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                .build();

        scheduler.scheduleJob(jobDetail, trigger);

        scheduler.start();


    }
}
